using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using THSLib;
namespace THSERP.BaseProvider
{
    public class BaseModuleFactory
    {
        public static BaseModuleERP GetModule(String strModuleName)
        {
            try
            {
                Type moduleType = THSApp.THSERPAssembly.GetType("THSERP.Modules." + strModuleName + "." + strModuleName + "Module");
               // return (BaseModuleERP)moduleType.InvokeMember("", BindingFlags.CreateInstance, null, null, null);  
                //Assembly entryAssembly = Assembly.GetEntryAssembly();
                //Application.DoEvents();
                //Type typeObj = entryAssembly.GetType("THSERP.Modules." + strModuleName + "." + strModuleName + "Module");
                //if (typeObj == null)
                //{
                //    typeObj = Assembly.LoadFrom("THS" + strModuleName + ".dll").GetType("THSERP.Modules." + strModuleName + "." + strModuleName + "Module");
                //}
                return (BaseModuleERP)DynamicInvoker.DynamicCreateInstanceObject(moduleType);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Contact THS to activate this module","#Message#",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return null;
            }
        }
        
    }
}
